package com.java.springcloud.controller;

import com.java.springcloud.service.MongoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dushougudu
 */
@RestController
@Slf4j
@RequestMapping("/mongo")
public class MongoController {
    @Autowired
    private MongoService mongoService;

    @PostMapping("/send")
    public String send(Integer count) {
        return mongoService.send(count);
    }

    @PostMapping("/sendFail")
    public String sendFail(Integer count) {
        try {
            return mongoService.sendFail(count);
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    @PostMapping("/sendFailMulti")
    public String sendFailMulti(Integer count) {
        try {
            return mongoService.sendFailMulti(count);
        } catch (Exception e) {
            return e.getMessage();
        }
    }

}
